package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Demo11 {
    public static void main(String[] args) {
        //事务控制
        Scanner scanner = new Scanner(System.in);
        try(Connection connection = DEUtil.getConnection()) {
            connection.setAutoCommit(false);
            String sql = "DELETE FROM user WHERE id=?";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            System.out.println("请输入要删除的id:");
            preparedStatement.setString(1,scanner.nextLine());
            int num = preparedStatement.executeUpdate();
            System.out.println(num>0 ?"删除成功" : "删除失败");
//            connection.rollback();
            connection.commit();

        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
